<?php
use Lib\ResLoader;
class App_Plugin_Acl extends Zend_Controller_Plugin_Abstract
{
    /**
     * @var Zend_Auth
     */
    protected $_auth = null;

    /**
     * @var Zend_Acl
     */
    protected $_acl = null;

    public function preDispatch(Zend_Controller_Request_Abstract $request)
    {
        return false;
        $aclManager = new \Managers\Acl();
        $this->_acl = $aclManager->getAcl();
        $this->_auth = Zend_Auth::getInstance();

        // Setting user role
        $role = 'Guest';
        if ($this->_auth->hasIdentity()) {
            $user = $this->_auth->getStorage()->read();
            $userManager = new \Managers\Users();
            $userRole = $userManager->getRole($user->id);

            if ($userRole) {
                $role = $userRole['name'];
            }
        }
        // Mapping to determine which Resource the current
        // request refers to (really simple for this example!)
        $resource = $request->controller;
        $privilege = $request->action;

        if (!$this->_acl->has($resource)) {
            $resource = null;
        }      

        // ACL Access Check
        if (!$this->_acl->isAllowed($role, $resource, $privilege)) {
            $flashMessenger = new Lib_Flash();
            $flashMessenger->addMessage('You do not have enough rights to do that.', Lib_Flash::ERROR, Lib_Flash::NOW);

        }
    }

    /**
     * @param \Zend_Acl $acl
     * @return void
     */
    public function setAcl($acl)
    {
        $this->_acl = $acl;
    }

    /**
     * @return \Zend_Acl
     */
    public function getAcl()
    {
        return $this->_acl;
    }

    /**
     * @param \Zend_Auth $auth
     * @return void
     */
    public function setAuth($auth)
    {
        $this->_auth = $auth;
    }

    /**
     * @return \Zend_Auth
     */
    public function getAuth()
    {
        return $this->_auth;
    }

}
